//
//  main.cpp
//  文件和流
//
//  Created by linjinzhu on 2017/7/13.
//  Copyright © 2017年 baidu. All rights reserved.
//

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, const char * argv[]) {

    char *filename = "data.dat";

    // 创建文件输出流
    ofstream outfile;
    // 打开文件
    outfile.open(filename);

    cout << "writing to file data.dat" << endl;
    cout << "enter your name:" << endl;

    char data[100];
    cin.getline(data, 100);
    outfile << data << endl;

    cout << "input your age:" << endl;
    cin >> data;
    outfile << data << endl;

    outfile.flush();

    // 关闭文件
    outfile.close();


    // 创建文件输入流
    ifstream infile;
    infile.open(filename);

    cout << "reading from file:" << endl;
    // 读取文件内容
    infile >> data;
    cout << data << endl;

    infile.seekg(1);
    infile.seekg(1, ios::cur);
    // 再次读取
    infile >> data;
    cout << data << endl;


    // 关闭文件输入流
    infile.close();



    return 0;
}
